/*
 * BinaryRule.java
 *
 * Created on June 24, 2006, 1:26 PM
 * Checked for nits on Sept 27, 2006 cb
 * Apparently nit free, Sept 27, 2006, dnmehay
 */

package galronnlp.cfg.grammar;

import java.util.List;
import java.util.LinkedList;

import galronnlp.util.Symbol;

/**
 * A Binary CFG rule, of the form X => Y Z
 *
 * @author Daniel A. Galron
 */
public class BinaryRule implements Rule {
    
    private final int arity = 2;
    private LinkedList<Symbol> RHS;
    private Symbol LHS;
    
    
    /** 
     * Creates a new instance of BinaryRule 
     * @param LHS the left hand side of the rule
     * @param RHS a <code>LinkedList</code> of <code>Symbol</code>s representing the right hand side of the rule
     */
    public BinaryRule(Symbol LHS, LinkedList<Symbol> RHS) {
        this.LHS = LHS;
        this.RHS = RHS;
    }

    /** 
     * Creates a new instance of BinaryRule 
     * @param LHS the left hand side of the rule
     * @param lRHS the left child of the production
     * @param rRHS the right child of the production
     */    
    public BinaryRule(Symbol LHS, Symbol lRHS, Symbol rRHS) {
        this.LHS = LHS;
        this.RHS = RHS;
    }

    /**
     * @return the RHS of the rule as a <code>List</code>
     */
    public List<Symbol> RHS() {
        return this.RHS;
    }
    /**
     * @return the LHS of the rule as a <code>Symbol</code>
     */    
    public Symbol LHS() {
        return this.LHS;
    }
    
    /**
     * @return the arity (2) of this rule
     */
    public int arity() {
        return this.arity;
    }
    
    public String toString() {
        String ret = this.LHS + " --> " + this.RHS.get(0) + ", " + this.RHS.get(1);
        return ret;
    }

    public boolean hasTerminalRHS() {
        return false;
    }
    
}
